package com.ti.winona.ui.fragment;

import com.loopj.android.image.SmartImageView;
import com.taplinker.client.App;
import com.taplinker.client.AppConfigFactory;
import com.taplinker.client.R;
import com.ti.winona.net.API;
import com.ti.winona.util.FragmentOperateUtil;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class PerSetFragment extends Fragment {
	
	public final static String TAG = "PersonalsetFragment";
	
	private View mPersonalView;
	
	private ImageView mImgHomeBack;
	
	private SmartImageView mImgPerSetCustomer;
	private TextView mTxtPerSetCustomerName;
	
	private View mLinCustomerView;
	private View mLinSystemView;
	private View mLinAboutView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return mPersonalView = inflater.inflate(R.layout.fragment_perset, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		findView();
		init();
		initListener();
	}

	private void findView() {
		mImgHomeBack = (ImageView) mPersonalView.findViewById(R.id.img_personalset_back);
		
		mImgPerSetCustomer = (SmartImageView) mPersonalView.findViewById(R.id.img_perSet_customer);
		mTxtPerSetCustomerName = (TextView) mPersonalView.findViewById(R.id.txt_perSet_customer_name);
		
		mLinCustomerView = mPersonalView.findViewById(R.id.lin_personalset_customer);
		mLinSystemView = mPersonalView.findViewById(R.id.lin_personalset_system);
		mLinAboutView = mPersonalView.findViewById(R.id.lin_personalset_about);
	}
	
	private void init() {
		mImgPerSetCustomer.setImageUrl(API.IMAGE + AppConfigFactory.getInstance().getUserInfo().getUserIcon());
		mTxtPerSetCustomerName.setText(AppConfigFactory.getInstance().getUserInfo().getNickname());
	}
	
	private void initListener() {
		// 返回
		mImgHomeBack.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FragmentOperateUtil.popFragmentBackStack(getActivity().getSupportFragmentManager());
			}
		});
		// 个人中心
		mLinCustomerView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				addFragment(PerCenterFragment.class, PerCenterFragment.TAG);
			}
		});
		// 系统设置
		mLinSystemView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				addFragment(SystemSetFragment.class, SystemSetFragment.TAG);
			}
		});
		// 关于
		mLinAboutView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				App.showToast("关于");
			}
		});
	}
	
	private void addFragment(Class<? extends Fragment> clazz, String tag) {
		FragmentOperateUtil.replaceFragmentWithAnim(getActivity().getSupportFragmentManager(), clazz, R.id.main_frame, tag, null, true);
	}
	
}
